<%@page import="com.xnx3.j2ee.Global" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="com.xnx3.wangmarket.admin.G" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<jsp:include page="../iw/common/head.jsp">
    <jsp:param name="title" value="修改网站基本信息"/>
</jsp:include>

<form id="form" action="updateCompanyInfo.do" method="post" class="layui-form" style="padding:20px; padding-top:35px;">
    <div style="margin: 0 auto;width: 600px">
        <%--上传公司logo--%>
        <form id="form" method="post" class="layui-form" enctype="multipart/form-data"
              style="padding-top:35px; margin-bottom: 10px; padding-right:35px;">

            <%--<label class="layui-form-label">公司logo</label>--%>
            <div id="uploadForm">
                <img src='<%=basePath%>${broadcastImgPath}' alt='' id='img' style="width: 100px;height: 100px;top: 20px;"/><br>
                <input id="file" type="file" name="files" multiple="multiple"/>
                <button id="upload" type="button" onclick="getUpload()">上传轮播图</button>
            </div>
        </form>
        <script type="text/javascript">
            function getUpload() {
                var formData = new FormData();
                var files = document.getElementById("file").files;
                for(var i=0;i<files.length;i++){
                    formData.append('file', $('#file')[0].files[i]);
                }

                $.ajax({
                    url: '<%=basePath %>CompanyInfoController/uploadBroadImage.do',
                    type: 'POST',
                    dataType: "json",
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false
                }).success(function (res) {
                    console.log(res)
                    res.suss==0? layer.msg('上传成功', {shade: 0.3}):layer.msg('请选择图片', {icon:0,shade: 0.3});
                    document.getElementById("img").src = res.data;
                }).fail(function (res) {
                    layer.msg('上传失败', {shade: 0.3});
                });
            }
        </script>
        <%----------------------------公司介绍-----------------------------------%>
        <form id="form" method="post" class="layui-form" enctype="multipart/form-data"
              style="padding-top:35px; margin-bottom: 10px; padding-right:35px;">

            <%--<label class="layui-form-label">公司logo</label>--%>
            <div id="uploadForm">
                <img src='<%=basePath%>${introduceImgPath}' alt='' id='img1' style="width: 100px;height: 100px;top: 20px;"/><br>
                <input id="file1" type="file"/>
                <button id="upload1" type="button" onclick="getUpload1()">上传介绍图</button>
            </div>
        </form>
        <script type="text/javascript">
            function getUpload1() {
                var formData = new FormData();
                formData.append('file', $('#file1')[0].files[0]);
                $.ajax({
                    url: '<%=basePath %>CompanyInfoController/uploadIntroduceImage.do',
                    type: 'POST',
                    dataType: "json",
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    res.result==1? layer.msg('上传成功', {shade: 0.3}):layer.msg('请选择图片', {icon:0,shade: 0.3});
                    document.getElementById("img1").src = res.data;
                }).fail(function (res) {
                    console("失败");
                });
            }
        </script>
        <div class="layui-form-item">
            <label class="layui-form-label">公司简介</label>
            <div class="layui-input-block">
            <textarea name="introduce" required lay-verify="introduce" placeholder="请输入您的公司简介"
                      class="layui-textarea">${introduce}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">保存修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
</form>

<script>
    try {
        //自适应弹出层大小
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.iframeAuto(index);
    } catch (err) {
    }

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form;

        //自定义验证规则
        form.verify({
            username: function (value) {
                if (value.length > 5) {
                    return '联系人姓名不能超过5个字！';
                }
            },
            phone: function (value) {
                if (value.length == 0 || value.length > 14) {
                    return '请输入14个数字以内的联系电话';
                }
            },
            qq: function (value) {
                if (value.length == 0 || value.length > 14) {
                    return '请输入12个数字或以内的QQ号';
                }
            },
            companyName: function (value) {
                if (value.length > 30) {
                    return '请输入30个字以内的公司名字';
                }
            },
            address: function (value) {
                if (value.length > 80) {
                    return '请输入80个字以内的公司或办公所在地址';
                }
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            $.showLoading('数据保存中');
            var d = $("form").serialize();
            $.post("<%=basePath %>CompanyInfoController/updateCompanyInfo.do", d, function (result) {
                $.hideLoading();
                var obj = JSON.parse(result);
                if (obj.result == '1') {
                    parent.layer.msg('操作成功', {shade: 0.3});
                } else if (obj.result == '0') {
                    parent.layer.msg(obj.info, {shade: 0.3})
                } else {
                    parent.layer.msg(result, {shade: 0.3})
                }
                parent.layer.close(index);
            }, "text");

            return false;
        });

    });
</script>

</body>
</html>